#include<stdio.h>
#include <sys/ipc.h>
#include<sys/shm.h>
#include<unistd.h>
#include<cstring>
#define pathname "./server.cpp"
#define number 0x66
#define SIZE 4096 
int main()
{
    //创建key值
    //创建共享内存
    //关联共享内存
    //去关联内存
    //释放内存（只用在服务端删除就行）
    
    key_t key=ftok(pathname,number);
    if(key<0)
    {
        perror("server create key failed");
        return 1;
    }
    int shm=shmget(key,SIZE,IPC_CREAT|0666);
    if(shm<0)
    {
        perror("create shm failed");
        return 2;
    }

    char* msg=(char*)shmat(shm,NULL,0);
    while(1)
    {
         if(strlen(msg))
         {
            printf("client say: %s",msg);
            break;
         }
    }
    shmdt(msg);
    shmctl(shm,IPC_RMID,NULL);//释放内存
    return 0;
}